<?php
/**
*
* @author Mihold (Mykhailo Kutsenko) miholdk@gmail.com
* @package - GoodPost
* @version $Id$
* @copyright (c) 2012 Mykhailo Kutsenko
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

/**
* @ignore
*/

if (!defined('IN_PHPBB'))
{
	exit;
}

class acp_goodpost
{
	public $u_action;

	public function main($id, $mode)
	{
		global $db, $user, $auth, $template, $cache;
		global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;

		$user->add_lang('acp/common');
		$submit = (isset($_POST['submit'])) ? true : false;
		$form_key = 'acp_goodpost';
		add_form_key($form_key);
		
		switch ($mode)
		{
			case 'config':
				$this->tpl_name = 'acp_goodpost';
				
				// Save MOD configuration
				if ($submit)
				{
					if (!check_form_key('acp_goodpost'))
					{
						trigger_error('FORM_INVALID');
					}

					// Check new values for correct data
					$new_mod_config = array();
					$var_val = (int)request_var('goodpost_active', 0);
					if ($var_val === 0 || $var_val === 1)
					{
						$new_mod_config['mod_goodpost_active'] = $var_val;
					}
					else
					{
						trigger_error('FORM_INVALID');
					}
					$var_val = (int)request_var('goodpost_sicon', 0);
					if ($var_val === 0 || $var_val === 1)
					{
						$new_mod_config['mod_goodpost_icon'] = $var_val;
					}
					else
					{
						trigger_error('FORM_INVALID');
					}
					$var_val = (int)request_var('goodpost_sbg', 0);
					if ($var_val === 0 || $var_val === 1)
					{
						$new_mod_config['mod_goodpost_bg'] = $var_val;
					}
					else
					{
						trigger_error('FORM_INVALID');
					}
					$var_val = (int)request_var('goodpost_stitle', 0);
					if ($var_val === 0 || $var_val === 1)
					{
						$new_mod_config['mod_goodpost_title'] = $var_val;
					}
					else
					{
						trigger_error('FORM_INVALID');
					}
					$var_val = (int)request_var('goodpost_sline', 0);
					if ($var_val === 0 || $var_val === 1)
					{
						$new_mod_config['mod_goodpost_line'] = $var_val;
					}
					else
					{
						trigger_error('FORM_INVALID');
					}
					$var_val = (int)request_var('goodpost_days_limit', 0);
					if ($var_val >= 0 && $var_val <= 30)
					{
						$new_mod_config['mod_goodpost_days_limit'] = $var_val;
					}
					else
					{
						trigger_error('FORM_INVALID');
					}
					$new_mod_config['mod_goodpost_vote_max'] = (int)request_var('goodpost_vote_max', 0);
					$new_mod_config['mod_goodpost_vote_min'] = (int)request_var('goodpost_vote_min', 0);
					// Save new configuration
					foreach ($new_mod_config as $conf_par => $conf_val)
					{
						set_config($conf_par, $conf_val);
					}
					// Clearing
					unset($new_mod_config, $conf_par, $conf_val, $var_val);

					trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
				}

				// Get MOD configuration
				$template->assign_vars(array(
					'GOODPOST_VERSION'		=> 'v' . $config['mod_goodpost_version'],
					'GOODPOST_DAYS_LIMIT' 	=> $config['mod_goodpost_days_limit'],
					'GOODPOST_VOTE_MAX'		=> $config['mod_goodpost_vote_max'],
					'GOODPOST_VOTE_MIN'		=> $config['mod_goodpost_vote_min'],
					'GOODPOST_ACTIVE'		=> $config['mod_goodpost_active'],
					'GOODPOST_SHOW_ICON' 	=> $config['mod_goodpost_icon'],
					'GOODPOST_SET_BG'		=> $config['mod_goodpost_bg'],
					'GOODPOST_SET_TITLE'	=> $config['mod_goodpost_title'],
					'GOODPOST_SHOW_LINE'	=> $config['mod_goodpost_line'],
					'U_ACTION'				=> $this->u_action,
				));
			break;
			default:
		}
	}
}

?>